package com.xjrsoft.module.app.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.module.app.entity.XjrAppFunctionForm;
import com.xjrsoft.module.app.mapper.XjrAppFunctionFormMapper;
import com.xjrsoft.module.app.service.IXjrAppFunctionFormService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zlf
 * @since 2022-07-21
 */
@Service
public class XjrAppFunctionFormServiceImpl extends ServiceImpl<XjrAppFunctionFormMapper, XjrAppFunctionForm> implements IXjrAppFunctionFormService {

    @Override
    public List<XjrAppFunctionForm> getAuthFormForCurUser(List<String> functionIdList) {
        if (SecureUtil.isAdminUser()) {
            return this.list(Wrappers.<XjrAppFunctionForm>query().lambda().in(XjrAppFunctionForm::getFunctionId, functionIdList));
        } else {
            return this.baseMapper.getFunctionFormOfAuth(functionIdList, SecureUtil.getUserId(), SecureUtil.getRoleIdList());
        }
    }

    @Override
    public List<XjrAppFunctionForm> getFormByFunctionId(String functionId) {
        return this.list(Wrappers.<XjrAppFunctionForm>query().lambda().eq(XjrAppFunctionForm::getFunctionId, functionId).orderByAsc(XjrAppFunctionForm::getSortCode));
    }
}
